From 9a38d22579a38a1411e6cb3663273e121bb680d3 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Fri, 11 Feb 2011 11:53:00 +0000 Subject: [PATCH] Since 1.17 a whole lot of extensions have sprouted *.i18n.magic.php files. Most of these files have entries which erroneously omit the English synonym for a magic word. This breaks the extension completely when an affected language is selected. This patch automatically includes synonyms from the fallback localisation, and prevents the case flag from being overridden, thus making extensions resistant to translator error. --- includes/LocalisationCache.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/includes/LocalisationCache.php b/includes/LocalisationCache.php index f81b9bf5af..d8551a0fb6 100644 --- a/includes/LocalisationCache.php +++ b/includes/LocalisationCache.php @@ -95,7 +95,7 @@ class LocalisationCache { * by a fallback sequence. */ static public $mergeableMapKeys = array( 'messages', 'namespaceNames', 'mathNames', - 'dateFormats', 'defaultUserOptionOverrides', 'magicWords', 'imageFiles', + 'dateFormats', 'defaultUserOptionOverrides', 'imageFiles', 'preloadedMessages', ); @@ -117,6 +117,11 @@ class LocalisationCache { */ static public $optionalMergeKeys = array( 'bookstoreList' ); + /** + * Keys for items that are formatted like $magicWords + */ + static public $magicWordKeys = array( 'magicWords' ); + /** * Keys for items where the subitems are stored in the backend separately. */ @@ -181,7 +186,8 @@ class LocalisationCache { self::$mergeableMapKeys, self::$mergeableListKeys, self::$mergeableAliasListKeys, - self::$optionalMergeKeys + self::$optionalMergeKeys, + self::$magicWordKeys ) ); } return isset( $this->mergeableKeys[$key] ); @@ -426,6 +432,8 @@ class LocalisationCache { if ( isset( $value['inherit'] ) ) { unset( $value['inherit'] ); } + } elseif ( in_array( $key, self::$magicWordKeys ) ) { + $this->mergeMagicWords( $value, $fallbackValue ); } } } else { @@ -433,6 +441,19 @@ class LocalisationCache { } } + protected function mergeMagicWords( &$value, $fallbackValue ) { + foreach ( $fallbackValue as $magicName => $fallbackInfo ) { + if ( !isset( $value[$magicName] ) ) { + $value[$magicName] = $fallbackInfo; + } else { + $oldSynonyms = array_slice( $fallbackInfo, 1 ); + $newSynonyms = array_slice( $value[$magicName], 1 ); + $synonyms = array_unique( array_merge( $oldSynonyms, $newSynonyms ) ); + $value[$magicName] = array_merge( array( $fallbackInfo[0] ), $synonyms ); + } + } + } + /** * Given an array mapping language code to localisation value, such as is * found in extension *.i18n.php files, iterate through a fallback sequence -- 2.20.1